const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const DonePlugin = require('./plugins/1.done-plugin.js');
const AssetPlugin = require('./plugins/2.asset-plugin');
//存档插件，把所有的输出的文件变成一个压缩包，放置到输出目录中去
const ArchivePlugin = require('./plugins/3.archive-plugin');
const AutoExternalPlugin = require('./plugins/4.auto-external-plugin');
const PreloadWebpackPlugin = require('./plugins/7.preload-webpack-plugin');
module.exports = {
    mode:'development',
    devtool:false,
    entry:{
        main:'./src/index.js',
    },
    output:{
        filename:'[name].js',
    },

  /*   externals:{
        'jquery':'$'
    }, */
    plugins:[
        new HtmlWebpackPlugin({
            template:'./src/index.html'
        }),
        new AutoExternalPlugin({
            jquery:{//自动把jquery模块变成一个外部依赖模块
                variable:'jQuery',//不再打包，而是从window.jQuery变量上获取jquery对象
                url:'https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js'//CDN脚本
            },
            lodash:{//自动把jquery模块变成一个外部依赖模块
                variable:'_',//不再打包，而是从window.jQuery变量上获取jquery对象
                url:'https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js'//CDN脚本
            }
        }),
        new DonePlugin({name:'ikki'}),
        new AssetPlugin(),
        // new ArchivePlugin({
        //     filename:'[timestamp].zip'
        // })
        new CleanWebpackPlugin({
            cleanOnceBeforeBuildPatterns: ['**/*']
        }),
        new PreloadWebpackPlugin({
            rel: 'prefetch',
            include: 'asyncChunks',
        }),
    ]
}